#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    ui->treeWidget->setHeaderLabel("QQ好友列表");

    QStringList list1;
    list1.append("幼儿园同学");
    QTreeWidgetItem *item1 = new QTreeWidgetItem(list1);
    ui->treeWidget->addTopLevelItem(item1);

    QTreeWidgetItem *item10 = new QTreeWidgetItem(QStringList() << "aaa");
    item10->setIcon(0, QIcon(":/img/aaa.png"));

    item1->addChild(item10);

    QTreeWidgetItem *item11 = new QTreeWidgetItem(QStringList() << "bbb");
    item11->setIcon(0, QIcon(":/img/bbb.png"));
    item1->addChild(item11);

    QStringList list2;
    list2.append("小学同学");
    QTreeWidgetItem *item2 = new QTreeWidgetItem(list2);
    ui->treeWidget->addTopLevelItem(item2);
    QStringList childList2;
    childList2.append("111");
    QTreeWidgetItem *childItem2 = new QTreeWidgetItem(childList2);
    item2->addChild(childItem2);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column)
{
    qDebug() << item->text(column);
}

void MainWindow::on_Search_pbtn_clicked()
{
}

void MainWindow::on_Search_pbtn_2_clicked()
{
    int pos = ui->searchlineEdit_2->text().toInt();
    ui->treeWidget->takeTopLevelItem(pos);
}

void MainWindow::on_Search_pbtn_5_clicked()
{
    int top = ui->searchlineEdit_2->text().toInt();
    int pos = ui->searchlineEdit_5->text().toInt();
    ui->treeWidget->topLevelItem(top)->takeChild(pos);
}

void MainWindow::on_Search_pbtn_6_clicked()
{
    QTreeWidgetItem *child = ui->treeWidget->currentItem();
    QTreeWidgetItem *parent = child->parent();
    if (parent)
    {
        int pos = parent->indexOfChild(child);
        parent->takeChild(pos);
    }
    else
    {
        int pos = ui->treeWidget->indexOfTopLevelItem(child);
        ui->treeWidget->takeTopLevelItem(pos);
    }
}
